//package com.hzy.auth;
//
//import com.hzy.exception.TokenIsExpireException;
//import com.hzy.token.Token;
//import com.hzy.token.TokenService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Objects;
//
//
//public class TokenAuthenticationProvider implements AuthenticationProvider{
//
//    @Autowired
//    private TokenService tokenService;
//
//    @Override
//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//        Token token = tokenService.createToken(authentication.getName());
//        if(Objects.isNull(token)){
//            throw new TokenIsExpireException("token is expired");
//        }
//        tokenService.updateLastModifiedDate(token.getToken());
////        authentication = new TokenAuthenticationToken(token.getUser_id(), buildAuthorities(token.getRole()));
//        authentication.setAuthenticated(true);
//        return authentication;
//    }
//
//
//    private Collection<SimpleGrantedAuthority> buildAuthorities(String role) {
//        Collection<SimpleGrantedAuthority> collection = new ArrayList<>();
//        collection.add(new SimpleGrantedAuthority(role));
//        return collection;
//    }
//
//    @Override
//    public boolean supports(Class<?> aClass) {
//        return TokenAuthenticationProvider.class.isAssignableFrom(aClass);
//    }
//}
